package base;

import java.util.Arrays;

public class SumCombinations {

	public static void main(String[] args) {
        int arr[] = {0,1,2,3,4,5,6,7,11,12,14,20};
        int index = Arrays.binarySearch(arr, 5);
        System.out.println(index);
        int A[] =Arrays.copyOf(arr, index+1);
        System.out.println(Arrays.toString(A));
        int i=0;
        int j= A.length -1;
        int N= 5;
        while(i<j){
        	if(A[i] + A[j] < N) {
        		/* if sum of elements at current indices is < required number, 
        		   we need to increase the sum, so i++
        		*/
        		i++;
        		}
        	else if (A[i] + A[j] > N){
        		//decrese the sum
        		j--;
        	}
        	else{
        		//we have a match, 
        		System.out.println(A[i]+" "+A[j]);
        		//print i and j and 
        		//decrease sum: j--;
        		i++;j--;
        	}
        }
	}

}
